SpatialFear.SFWindow

00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
//=============================================================================
// Spatial Fear
// Name: SFWindow
// Description: Abstract base class for Spatial Fear  output windows.
//
// Author: Markus Nuebel
//=============================================================================


class SFWindow extends SFObject
abstract;

const constScreenMaxX     = 1280;
const constScreenMaxY     = 1024;

enum ESlideDir
{
     SLIDE_Up,
     SLIDE_Down,
     SLIDE_Left,
     SLIDE_Right,
};

enum EState
{
     SLIDE_In,
     SLIDE_Out,
     In,
     Out,
};

struct Region
{
     var() int X;
     var() int Y;
     var() int W;
     var() int H;
};


var Pawn m_oPawnOwner;	// Private: Pawn currently managing this window
var SFFontInfo m_Fonts; // Private; Font factory
var Texture m_texBkg; // Private: Window texture background
var bool	m_bVisible; // Private: Enables/Disables rendering of the window
var float   m_fHUDScale; // Private: current HUD scale. Depends on screen resolution and user defined HUD size.
var float	m_fVHUDScale; // Private: Correction of ChallengeHUD bug;
var int     m_X; // Private destination window position x
var int     m_Y; // Private destination window position y
var int     m_nWidth;  // Private: width
var int		m_nHeight; // Private: height
var int		m_fAspectRatio; // Private: aspect ratio of the window
var int     m_nWidthScaled;  // Private: width (scaled)
var int		m_nHeightScaled; // Private: height (scaled)
var int		m_nBorderSizeScaled; // Private: border size (scaled)
var int		m_nStepCur; // Private current sliding step
var int     m_nSlideTime; // Private: Time it takes to slide the window in. Time in msecs. Default: 1000msecs.
var int     m_nTimerInterval; // Private: timer interval for slide in/out actions
var float     m_XCur; // Private current window position x
var float     m_YCur; // Private current window position y
var float     m_XCurScaled; // Private current window position x (scaled)
var float     m_YCurScaled; // Private current window position y (scaled)
var float     m_fXStep; // Privat: Size of sliding step for x direction
var float     m_fYStep; // Privat: Size of sliding step for y direction
var int		m_nSlideSteps; // Private: Number of steps, needed to slide in the window
var EState	m_nState; // Private: Current slide action, in/out
var int		m_nBorderSize; // Private: Size of border
var int		m_nBkgTopOffset;	// Private: Offset of the top of the background.
var SFWindow	m_wndParent;	// Private: Parent window
var Sound	m_sndOpen;	// Private: Sound effect for opening window
var Sound	m_sndClose;	// Private: Sound effect for closing window
var float	m_fOpenSoundVol; // Volume of opening sound
var float	m_fCloseSoundVol; // Volume of closing sound

// All initialization stuff
simulated function init(float fHUDScale, int X, int Y, int nWidth, int nHeight, optional Pawn Owner, optional string strText, optional SFWindow wndParent)
{
      // Setup font factory
//      m_Fonts = FontInfo(spawn(Class<Actor>(DynamicLoadObject("Botpack.FontInfo", class'Class'))));
     m_Fonts	= spawn(class<SFFontInfo>(DynamicLoadObject("SpatialFear.SFFontInfo", class'Class')));

      // Init some members
      m_fHUDScale       = fHUDScale;
      m_X               = X;
      m_Y               = Y;
      m_XCur            = m_X;
      m_YCur            = m_Y;
      m_nWidth          = nWidth;
      m_nHeight         = nHeight;
	  m_fAspectRatio	= m_nWidth/m_nHeight;
      m_nState          = Out;
	  m_oPawnOwner		= Owner;
      m_wndParent       = wndParent;
}

// Cleanup
simulated function terminate()
{
	m_Fonts			= None;
	m_oPawnOwner	= None;
	m_wndParent		= None;
}

// Set the parent window
simulated function setParent(SFWindow oParent)
{
	m_wndParent	= oParent;
}

// Shows the window
simulated function show()
{
	m_bVisible    = true;
	if(None != m_sndOpen)
		if(None != m_oPawnOwner)
			m_oPawnOwner.PlaySound(m_sndOpen, SLOT_Misc, m_fOpenSoundVol);
		else
			PlaySound(m_sndOpen, SLOT_Misc, m_fOpenSoundVol);
}

// Hides the window
simulated function hide()
{
	if(None != m_sndClose)
		if(None != m_oPawnOwner)
			m_oPawnOwner.PlaySound(m_sndClose, SLOT_Misc, m_fCloseSoundVol);
		else
			PlaySound(m_sndClose, SLOT_Misc, m_fCloseSoundVol);

	m_bVisible    = false;
}

// Get visible state
simulated function bool isVisible()
{
          return m_bVisible;
}

// Sets a new position
simulated function setPos(int X, int Y)
{
	m_XCur	= X;;
	m_YCur	= Y;
}

// Slides in the text window
simulated function slideIn(ESlideDir slide)
{

     m_nSlideSteps     = m_nSlideTime / 100;

     // Set the initial starting position, out of the screen boundaries.
     switch(slide)
     {
     case SLIDE_Up:
          //class'sfUtils'.static.sfLogEx(5, "SFWindow - slideIn - UP");
          m_YCur               = constScreenMaxY +2;     // below screen
          m_XCur               = m_X;
          m_fXStep          = 0;
          m_fYStep          = (m_Y - m_YCur) / m_nSlideSteps     ;
          break;
     case SLIDE_Down:
          //class'sfUtils'.static.sfLogEx(5, "SFWindow - slideIn - DOWN");
          m_YCur               = -m_nHeight-2;               // above screen
          m_XCur               = m_X;
          m_fXStep          = 0;
          m_fYStep          = (m_Y - m_YCur) / m_nSlideSteps     ;
          break;
     case SLIDE_Left:
          //class'sfUtils'.static.sfLogEx(5, "SFWindow - slideIn - LEFT");
          m_XCur               = constScreenMaxX +2;     // right out of screen
          m_YCur               = m_Y;
          m_fXStep          = (m_X - m_XCur) / m_nSlideSteps     ;
          m_fYStep          = 0;
          break;
     case SLIDE_Right:
          //class'sfUtils'.static.sfLogEx(5, "SFWindow - slideIn - RIGHT");
          m_XCur               = -m_nWidth-2;               // left out of screen
          m_YCur               = m_Y;
          m_fXStep          = (m_X - m_XCur) / m_nSlideSteps;
          m_fYStep          = 0;
          break;
     }

     // Update state
     m_nState          = SLIDE_In;
     m_nStepCur          = 0;

     // class'sfUtils'.static.sfLogEx(5, "SFWindow - slideIn - SliderSteps " $ m_nSlideSteps $ " XStep " $ m_fXStep $  "YStep" $ m_fYStep);

     // Start the timer
     SetTimer(0.1, True);

     // Shows the window
     show();

}

// Overwritten in child class, to do different backgrounds and effects
simulated function renderBackground(Canvas C)
{
	local int	X, Y, W, H;
	local int	nXBorder, nYBorder;

	if(None == m_texBkg)
		return;

	// Calculate border sizes
	nXBorder	= m_nBorderSizeScaled;
	nYBorder	= int(float(nXBorder) / m_fAspectRatio);

    //class'SfUtils'.static.sfLogEx(5, "SFWindow - renderBackground: Tex.U" $  m_texBkg.USize $ " Tex.V" $  m_texBkg.VSize $  " Width" $ m_nWidth $  " Height" $ m_nHeight);
	X = m_XCurScaled-nXBorder;
	Y = m_YCurScaled-nYBorder-(m_nBkgTopOffset*m_fHUDScale);
	W = m_nWidthScaled+2*nXBorder;
	H = m_nHeightScaled+2*nYBorder+(m_nBkgTopOffset*m_fHUDScale);

	C.SetPos(X, Y);
	C.DrawTile(m_texBkg, W, H, 0,0, m_texBkg.USize,m_texBkg.VSize);
    //class'SfUtils'.static.sfLogEx(5, "SFWindow - renderBackground: X" $  m_XCurScaled $ " Y" $ m_YCurScaled $  " Width" $ m_nWidthScaled $  " Height" $ m_nHeightScaled);

}

// Overwritten in child class, to do different forground
simulated function renderForeground(Canvas C)
{
}

// Owerwritten in child class to set up the canvas
simulated function prepareCanvas(Canvas C)
{
}


// Called during each frame to render the window.
simulated final function render(Canvas C, float fHUDScale)
{
	local Color	m_colSave;

    if(!m_bVisible)
          return;          // Early out

	// Save hud scaling
	m_fHUDScale		= fHUDScale;
	// Calc scaled window positions and size
	m_XCurScaled	= m_XCur * m_fHUDScale;
	m_YCurScaled	= m_YCur * m_fHUDScale;
	m_nWidthScaled	= m_nWidth	* m_fHUDScale;
	m_nHeightScaled	= m_nHeight	* m_fHUDScale;
	m_nBorderSizeScaled	= m_nBorderSize * m_fHUDScale;

	m_fVHUDScale = ((m_fHUDScale/C.ClipX*1280.0)*C.ClipY)/1024.0f;

	// Save the original Canvas
	m_colSave = C.DrawColor;

	// Prepare canvas for output
     prepareCanvas(C);

	// First render background
	renderBackGround(C);

   // Then render foreground
	renderForeGround(C);

	// Restore the old canvas
	C.DrawColor = m_colSave ;
}


// Timer event
event Timer()
{
     // Check the timer
     if((m_nSlideSteps-1)<m_nStepCur)
     {
          SetTimer(0, False);
          m_nState = In;
          return;
     }

     // Check state
     switch(m_nState)
     {
     case SLIDE_In:
          // Move the window on step further
          m_YCur     += m_fYStep;
          m_XCur     += m_fXStep;
          break;

     case SLIDE_Out:
          // Move the window on step back
          m_YCur     -= m_fYStep;
          m_XCur     -= m_fXStep;
          break;
     }

     m_nStepCur++;
     // Check for finished movement


     // class'sfUtils'.static.sfLogEx(5, "SFWindow - Timer: x:" $ m_XCur $ " y: " $ m_YCur $ "m_nStepCur " $ m_nStepCur);

}

simulated function DrawClippedActor( Canvas C, float XB, float YB, float X, float Y, Actor A, bool WireFrame, rotator RotOffset, vector LocOffset )
{
     local vector MeshLoc;
     local float FOV;
	 local float fWidth;

	 if(None != m_oPawnOwner)
		FOV = PlayerPawn(m_oPawnOwner).FOVAngle * Pi / 180;
	 else
	     class'sfUtils'.static.sfError( "SFWindow - DrawClippedActor: window owner not set!");

	fWidth = 2.0 + (A.CollisionRadius/10);
	MeshLoc.X = fWidth / tan(FOV/2);

	//MeshLoc.X = 4 / tan(FOV/2);
     MeshLoc.Y = 0;
     MeshLoc.Z = 0;

     A.SetRotation(RotOffset);
     A.SetLocation(MeshLoc + LocOffset);

	 C.DrawClippedActor(A, WireFrame, X, Y, XB, YB, True);
}

// Trims spaces from a string
function String TrimSpaces(String strText)
{
	local int nIndex;
	local int nLength;

	if ( strText == "" )
		return strText;

	// Trim appended spaces
	nIndex = Len(strText) - 1;
	while ((nIndex >= 0) && (Mid(strText, nIndex, 1) == " ") )
		nIndex--;

	if ( nIndex < 0 )
		return "";

	// Remove appended spaces
	strText = Mid(strText, 0, nIndex + 1);

	// Trim leading spaces
	nIndex = 0;
	while((nIndex < Len(strText) - 1) && (Mid(strText, nIndex, 1) == " "))
		nIndex++;

	// Remove leading spaces
	nLength = len(strText) - nIndex;
	strText = Right(strText, nLength);

	return strText;
}

defaultproperties
{
     m_nSlideTime=1000
     m_fOpenSoundVol=2.000000
     m_fCloseSoundVol=2.000000
}

class file time: 12/7/2003 3:58:24 PM - creation time: 12/7/2003 4:03:46 PM
Created with UnCodeX